package com.xlh.dao.courseTest.helper;

import com.google.common.collect.Lists;
import com.xlh.dao.courseTest.CourseQuestionRepositoryMapper;
import com.xlh.enums.courseTest.QuestionBusinessTypeEnum;
import com.xlh.pojo.courseTest.CourseQuestionRepository;
import com.xlh.pojo.courseTest.CourseQuestionRepositoryExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author cfz
 */
@Repository
public class CourseQuestionRepositoryMapperHelper {

    @Autowired
    private CourseQuestionRepositoryMapper courseQuestionRepositoryMapper;

    public List<CourseQuestionRepository> findQuestionByChapterId(Long chapterId){

        CourseQuestionRepositoryExample example = new CourseQuestionRepositoryExample();
        example.createCriteria().andBusinessTypeEqualTo(QuestionBusinessTypeEnum.PRACTICE.getCode()).andChapterIdEqualTo(chapterId).andDelMarkEqualTo(false);
        example.setOrderByClause("create_time");
        List<CourseQuestionRepository> courseQuestionRepositories = courseQuestionRepositoryMapper.selectByExample(example);
        return courseQuestionRepositories;
    }

    public List<CourseQuestionRepository> findQuestionByChapterIds(List<Long> chapterIds, int businessType){

        CourseQuestionRepositoryExample example = new CourseQuestionRepositoryExample();
        example.createCriteria().andBusinessTypeEqualTo(QuestionBusinessTypeEnum.PRACTICE.getCode()).andChapterIdIn(chapterIds).andDelMarkEqualTo(false);
        List<CourseQuestionRepository> courseQuestionRepositories = courseQuestionRepositoryMapper.selectByExample(example);

        return courseQuestionRepositories;
    }

    public void updateByCourseId(CourseQuestionRepository courseQuestionRepository, Long courseId) {

        CourseQuestionRepositoryExample example = new CourseQuestionRepositoryExample();
        example.createCriteria().andCourseIdEqualTo(courseId);
        courseQuestionRepositoryMapper.updateByExampleSelective(courseQuestionRepository, example);

    }
}
